// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import API from './API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async remoteList({ state: { param, info } }) {
    const repair = await API.getInfo()
    info.STATUS = transStatus(info, repair)

    const TIP = `查询${CORE.dict(info.STATUS, param.statusList)}工单`
    const [num, arr] = await API.getList(param, TIP)
    return [num, transList(arr)]
  },
}

// ============================== 转换方法 ============================== //

const transStatus = (info, repair) => {
  return info.STATUS.map(([code, name, , color]) => {
    const statusList = code.split(',')
    const total = statusList.reduce((num, status) => {
      return num + (repair[status] || 0)
    }, 0)
    return [code, name, total, color]
  })
}

const transList = (arr) => {
  return arr
}
